package com.usian.service.impl;

import com.usian.comment.Comment;
import com.usian.feedback.Feedback;
import com.usian.mapper.SquareMapper;
import com.usian.service.SquareService;
import com.usian.square.Square;
import com.usian.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SquareServiceImpl implements SquareService {
    @Autowired
    private SquareMapper squareMapper;
    @Override
    public List<Square> findAll(Square square) {
        List<Square> list = squareMapper.findAll(square);
        for (Square square1 : list) {
            if (square1.getUserId() != null) {
                User user = squareMapper.selectUserById(square1.getUserId());
                square1.setName(user.getName());
                square1.setImg(user.getImg());
                square1.setIntroduction(user.getIntroduction());
            }
        }
        return list;
    }

    @Override
    public int add(Square square) {
        return squareMapper.add(square);
    }

    @Override
    public List<Square> findById(Integer userId) {
        return squareMapper.findById(userId);
    }

    @Override
    public User selectUserByIdTwo(Integer id) {
        return squareMapper.selectUserByIdTwo(id);
    }

    @Override
    public List<Comment> comments(Integer id, Integer status) {
        return squareMapper.comments(id,status);
    }

    @Override
    public User selectUserThree(Integer userId) {
        return squareMapper.selectUserByIdThree(userId);
    }

    @Override
    public int addComment(Comment comment) {
        return squareMapper.addComment(comment);
    }

    @Override
    public int praise(Integer id) {
        return squareMapper.praise(id);
    }

    @Override
    public List<Map<String, Object>> comment() {
        return squareMapper.comment();
    }

    @Override
    public int feedback(Feedback feedback) {
        return squareMapper.feedback(feedback);
    }
}
